<?php
include( "agent/onlinebet_header2.php" );
if ($curruser['acl'] != 255)
{
    $userlist = GetUserList($curruser['id']);
    if ($userlist == "")
    {
        $ui->showErrorPage("<p>还没有建立会员！</p>");
        exit();
    }
}
$g_disk_code = array(1 => "a", 2 => "b", 3 => "c", 4 => "d");
$disk_code = "a";
$diskStr = "";
if (0 < $disk)
{
    $disk_code = $g_disk_code[$disk];
    $diskStr = $disk_code;
}
include( "class_6h/BetTotal_6h.php" );
$BetTotal_6h = new BetTotal_6h($lotto_id);
$colors = array("", "red", "blue", "green");
$dataTotalArr = array();
$showDataArr = array();
$theacl = $curruser['acl'];
$userid = $curruser['id'];
$showid = $theacl == 255 ? "0" : $userid;
switch ($bets)
{
    case 0 :
        $betids = array(1002, 5, 6, 15, 16, 17, 23);
        $bettypeStr = "1002,5,6,15,16,17,23";
        $listbetmod = 77;
        $betsGame = "1002";
        break;
    case 1 :
        $betids = array(4, 5, 6, 15, 16, 17, 23);
        $bettypeStr = "4,5,6,15,16,17,23";
        $listbetmod = 4;
        $betsGame = "4";
        break;
    case 2 :
        $betids = array(5, 6, 15, 16, 17, 23, 31);
        $bettypeStr = "5,6,15,16,17,23,31";
        $listbetmod = 31;
        $betsGame = "31";
        break;
    default :
        $betids = array(1002, 6, 15, 16, 17, 23);
        $bettypeStr = "1002,5,6,15,16,17,23";
        $listbetmod = 77;
        $betsGame = "1002";
        break;
}
$totalBetTyprArr = array(5, 6);
$totalRs = $BetTotal_6h->getDataListTotal($lotto_id, "{$betsGame},5,6", $showid, $split, $diskStr);
while (!$totalRs->eof)
{
    $tempIdx = $totalRs->f['bettype'];
    $dataTotalArr[$tempIdx] = $totalRs->f;
    $totalRs->next();
}
$totalRs->close();
foreach ($betids as $betid)
{
    if (14 < $betid && $betid < 24)
    {
        switch ($betid)
        {
            case 15 :
                $jStart = "1";
                $jEnd = "3";
                break;
            case 16 :
                $jStart = "3";
                $jEnd = "5";
                break;
            case 17 :
                $jStart = "5";
                $jEnd = "8";
                break;
            case 23 :
                $jStart = "8";
                $jEnd = "10";
                break;
        }
        $i = 1;
        while ($i < 7)
        {
            $j = $jStart;
            while ($j < $jEnd)
            {
                $showDataArr["{$betid}_{$i}"]["{$i} {$j}"] = array("numbers" => "{$i} {$j}", "totalnum" => 0, "amount" => 0, "amount_rate" => 0, "rate" => 0, "back1" => 0, "back2" => 0, "winlost" => 0, "namount" => "");
                ++$j;
            }
            $dataTotalArr["{$betid}_{$i}"] = array("bettype" => "{$betid}_{$i}", "totalnum" => 0, "amount" => 0, "amount_rate" => 0, "back1" => 0, "back2" => 0);
            ++$i;
        }
    }
    else if ($betid == $betsGame)
    {
        $lostwin = array();
        $winlost = 0;
        if (isset($dataTotalArr[$betsGame]))
        {
            $winlost = ( $dataTotalArr[$betsGame]['amount'] - $dataTotalArr[$betsGame]['back1'] + $dataTotalArr[$betsGame]['back2'] ) / 6;
        }
        else
        {
            $dataTotalArr[$betsGame] = array("bettype" => $betsGame, "totalnum" => 0, "amount" => 0, "amount_rate" => 0, "back1" => 0, "back2" => 0);
        }
        $i = 1;
        while ($i < 50)
        {
            $showDataArr[$betsGame][$i] = array("numbers" => $i, "totalnum" => 0, "amount" => 0, "amount_rate" => 0, "rate" => 0, "back1" => 0, "back2" => 0, "winlost" => $winlost, "namount" => "");
            $lostwin[$betsGame][$i] = $winlost;
            ++$i;
        }
    }
    else
    {
        $winlost5 = 0;
        $winlost6 = 0;
        if (isset($dataTotalArr[5]))
        {
            $winlost5 = ( $dataTotalArr[5]['amount'] - $dataTotalArr[5]['back1'] + $dataTotalArr[5]['back2'] ) / 6;
        }
        else
        {
            $dataTotalArr[5] = array("bettype" => 5, "totalnum" => 0, "amount" => 0, "amount_rate" => 0, "back1" => 0, "back2" => 0);
        }
        if (isset($dataTotalArr[6]))
        {
            $winlost6 = ( $dataTotalArr[6]['amount'] - $dataTotalArr[6]['back1'] + $dataTotalArr[6]['back2'] ) / 6;
        }
        else
        {
            $dataTotalArr[6] = array("bettype" => 6, "totalnum" => 0, "amount" => 0, "amount_rate" => 0, "back1" => 0, "back2" => 0);
        }
        $showDataArr[5][1] = array("numbers" => 1, "totalnum" => 0, "amount" => 0, "amount_rate" => 0, "rate" => 0, "back1" => 0, "back2" => 0, "winlost" => $winlost5, "namount" => "");
        $showDataArr[5][2] = array("numbers" => 2, "totalnum" => 0, "amount" => 0, "amount_rate" => 0, "rate" => 0, "back1" => 0, "back2" => 0, "winlost" => $winlost5, "namount" => "");
        $showDataArr[6][1] = array("numbers" => 1, "totalnum" => 0, "amount" => 0, "amount_rate" => 0, "rate" => 0, "back1" => 0, "back2" => 0, "winlost" => $winlost6, "namount" => "");
        $showDataArr[6][2] = array("numbers" => 2, "totalnum" => 0, "amount" => 0, "amount_rate" => 0, "rate" => 0, "back1" => 0, "back2" => 0, "winlost" => $winlost6, "namount" => "");
    }
}
$sql = $BetTotal_6h->getDataListByNumSsSQL($lotto_id, $bettypeStr, $showid, $diskStr, $split, $ratemod);
$rs = getdb($sql);
$updatetime = systime() - 30;
while (!$rs->eof)
{
    $bettype = $rs->f['bettype'];
    $winlost = 0;
    $i = $rs->f['numbers'];
    if ($betsGame == $bettype)
    {
        $i = intval($i);
        $winlost = ( $dataTotalArr[$bettype]['amount'] - $dataTotalArr[$bettype]['back1'] + $dataTotalArr[$bettype]['back2'] ) / 6 - $rs->f['amount_rate'];
        $lostwin[$bettype][$i] = $winlost;
    }
    else
    {
        if (in_array($bettype, $totalBetTyprArr))
        {
            $winlost = $dataTotalArr[$bettype]['amount'] - $rs->f['amount_rate'] - $dataTotalArr[$bettype]['back1'] + $dataTotalArr[$bettype]['back2'];
            $lostwin[$bettype][$i] = $winlost;
        }
        else
        {
            if (14 < $bettype && $bettype < 24)
            {
                $tempNumber = substr($i, 0, 1);
                $bettype = "{$bettype}_{$tempNumber}";
            }
            else
            {
                $i = intval($i);
            }
            $dataTotalArr[$bettype]['totalnum'] += $rs->f['totalnum'];
            $dataTotalArr[$bettype]['amount'] += $rs->f['amount'];
            $dataTotalArr[$bettype]['back1'] += $rs->f['back1'];
            $dataTotalArr[$bettype]['back2'] += $rs->f['back2'];
        }
    }
    $showDataArr[$bettype][$i]['totalnum'] = $rs->f['totalnum'];
    $showDataArr[$bettype][$i]['amount'] = $rs->f['amount'];
    $showDataArr[$bettype][$i]['amount_rate'] = $rs->f['amount_rate'];
    $showDataArr[$bettype][$i]['rate'] = $rs->f['rate'];
    $showDataArr[$bettype][$i]['back1'] = $rs->f['back1'];
    $showDataArr[$bettype][$i]['back2'] = $rs->f['back2'];
    $showDataArr[$bettype][$i]['winlost'] = $winlost;
    if ($updatetime < $rs->f['updatetime'])
    {
        $showDataArr[$bettype][$i]['namount'] = " class=\"namount\"";
    }
    $rs->next();
}
$rs->close();
if ($ratemod == 0)
{
    if ($bets == 2)
    {
        $rs = getdb("select * from rate31{$disk_code} where lotto_id={$lotto_id}");
    }
    else
    {
        $rs = getdb("select * from rate4{$disk_code} where lotto_id={$lotto_id}");
    }
    if ($theacl == 255)
    {
        $i = 1;
        while ($i < 50)
        {
            $showDataArr[$betsGame][$i]['rate'] = $rs->f["r" . d2($i)] - 0;
            ++$i;
        }
        $rs = getdb("select * from rate5{$disk_code} where lotto_id={$lotto_id}");
        $showDataArr[5][1]['rate'] = trimfloat($rs->f['r5_1'], 1);
        $showDataArr[5][2]['rate'] = trimfloat($rs->f['r5_2'], 1);
        $showDataArr[6][1]['rate'] = trimfloat($rs->f['r6_1'], 1);
        $showDataArr[6][2]['rate'] = trimfloat($rs->f['r6_2'], 1);
    }
    else
    {
        $rsu = get_srates_data($userid, $lotto_id, 4);
        $i = 1;
        while ($i < 50)
        {
            $showDataArr[$betsGame][$i]['rate'] = $rs->f["r" . d2($i)] - $rsu->f["r" . d2($i)] - 0;
            ++$i;
        }
        $rs = getdb("select * from rate5{$disk_code} where lotto_id={$lotto_id}");
        $rsu = get_srates_data($userid, $lotto_id, 5);
        $showDataArr[5][1]['rate'] = trimfloat($rs->f['r5_1'] - 0 - $rsu->f['r5_1'], 1);
        $showDataArr[5][2]['rate'] = trimfloat($rs->f['r5_2'] - 0 - $rsu->f['r5_2'], 1);
        $showDataArr[6][1]['rate'] = trimfloat($rs->f['r6_1'] - 0 - $rsu->f['r6_1'], 1);
        $showDataArr[6][2]['rate'] = trimfloat($rs->f['r6_2'] - 0 - $rsu->f['r6_2'], 1);
        $rsu->close();
    }
    $rs = getdb("select * from rate15{$disk_code} where lotto_id=" . $lotto_id);
    if ($rs->eof)
    {
        exit("Error ID(1)!");
    }
	
    $rss = get_srates_data($userid, $lotto_id, 23);
    if ($rss->eof)
    {
        exit("Error ID(2)!");
    }
    $i = 1;
    while ($i < 7)
    {
        $showDataArr["15_{$i}"]["{$i} 1"]['rate'] = $rs->f["r15_{$i}_1"] - $rss->f["r15_{$i}_1"] - 0;
        $showDataArr["15_{$i}"]["{$i} 2"]['rate'] = $rs->f["r15_{$i}_2"] - $rss->f["r15_{$i}_2"] - 0;
        $showDataArr["16_{$i}"]["{$i} 3"]['rate'] = $rs->f["r15_{$i}_3"] - $rss->f["r15_{$i}_3"] - 0;
        $showDataArr["16_{$i}"]["{$i} 4"]['rate'] = $rs->f["r15_{$i}_4"] - $rss->f["r15_{$i}_4"] - 0;
        $showDataArr["17_{$i}"]["{$i} 5"]['rate'] = $rs->f["r15_{$i}_5"] - $rss->f["r15_{$i}_5"] - 0;
        $showDataArr["17_{$i}"]["{$i} 6"]['rate'] = $rs->f["r15_{$i}_6"] - $rss->f["r15_{$i}_6"] - 0;
        $showDataArr["17_{$i}"]["{$i} 7"]['rate'] = $rs->f["r15_{$i}_7"] - $rss->f["r15_{$i}_7"] - 0;
        $showDataArr["23_{$i}"]["{$i} 8"]['rate'] = $rs->f["r15_{$i}_8"] - $rss->f["r15_{$i}_8"] - 0;
        $showDataArr["23_{$i}"]["{$i} 9"]['rate'] = $rs->f["r15_{$i}_9"] - $rss->f["r15_{$i}_9"] - 0;
        ++$i;
    }
    $rs->close();
}
if (isset($showDataArr[$betsGame]) && 0 < $dataTotalArr[$betsGame]['amount'])
{
    asort($lostwin[$betsGame]);
    reset($lostwin[$betsGame]);
    $k = 1;
    $showDataArrTemp = array();
    foreach ($lostwin[$betsGame] as $key => $val)
    {
        $showDataArrTemp[$betsGame][$k] = $showDataArr[$betsGame][$key];
        ++$k;
    }
    $showDataArr[$betsGame] = $showDataArrTemp[$betsGame];
}
$list = "";
$bettype = $betsGame;
$j = 1;
while ($j <= 10)
{
    $i = 0;
    while ($i < 5)
    {
        if ($i == 0)
        {
            $list .= "<tr class=td12 align=right>";
        }
        $k = $i * 10 + $j;
        if (49 < $k)
        {
            $list .= "<td></td><td></td><td></td><td></td><td></td>";
        }
        else
        {
            $numer = $showDataArr[$bettype][$k]['numbers'];
            $tempIdx = $k;
            $alert = "";
            $alert = $showDataArr[$bettype][$k]['namount'];
            if ($split == 1)
            {
                if (0 < $curruser['alert2'] && $curruser['alert2'] <= $showDataArr[$bettype][$tempIdx]['amount'])
                {
                    $alert = " class=alert2";
                }
                else if (0 < $curruser['alert1'] && $curruser['alert1'] <= $showDataArr[$bettype][$tempIdx]['amount'])
                {
                    $alert = " class=alert1";
                }
                $list .= "<td class=td6 align=center><font color=" . $colors[$g_numcolor[$numer]] . "><b>" . d2($numer) . "</b></font></td>";
            }
            else
            {
                $list .= "<td class=td6 align=center><font color=" . $colors[$g_numcolor[$numer]] . "><b>" . d2($numer) . "</b></font></td>";
            }
            if (0 < $showDataArr[$bettype][$k]['totalnum'])
            {
                $list .= "<td nowrap>" . $showDataArr[$bettype][$tempIdx]['totalnum'] . "</td>";
                $list .= "<td{$alert} nowrap><a href=" . get_listurl2($open, $listbetmod, d2($numer), 0) . ">" . round($showDataArr[$bettype][$tempIdx]['amount']) . "</a></td>";
            }
            else
            {
                $list .= "<td nowrap> 0</td>";
                $list .= "<td nowrap> 0</td>";
                $showDataArr[$bettype][$tempIdx]['winlost'] = ( $dataTotalArr[$bettype]['amount'] - $dataTotalArr[$bettype]['back1'] ) / 6;
            }
            $list .= "<td nowrap> " . sprintf("%.2f", $showDataArr[$bettype][$tempIdx]['rate']) . "</td>";
            if ($showDataArr[$bettype][$k]['winlost'] < 0)
            {
                $list .= "<td nowrap><font color='#EE2200'>" . round($showDataArr[$bettype][$tempIdx]['winlost']) . "</font></td>";
            }
            else
            {
                $list .= "<td nowrap><font color='#00AA22'>" . round($showDataArr[$bettype][$tempIdx]['winlost']) . "</font></td>";
            }
        }
        ++$i;
    }
    ++$j;
}
$prate_list = "<td nowrap>赔率</td>";
$tpl->set("prate_table", $prate_list);
$tpl->set("list", $list);
$tpl->set("total", round($dataTotalArr[$bettype]['amount']));
$tpl->set("sum_count", intval($dataTotalArr[$bettype]['totalnum']));
$bettype = 5;
$list = "";
$list .= "<tr class=td2>";
$list .= "<td class=td15 align=center>总单</td>";
$temp = round($dataTotalArr[$bettype]['amount'] - $showDataArr[$bettype]['1']['amount_rate'] - $dataTotalArr[$bettype]['back1'] + $dataTotalArr[$bettype]['back2']);
if (0 < $showDataArr[$bettype]['1']['totalnum'])
{
    $alert = $showDataArr[$bettype]['1']['namount'];
    $list .= "<td align=right nowrap>" . $showDataArr[$bettype]['1']['totalnum'] . "</td>";
    $list .= "<td align=right {$alert} nowrap><a href=" . get_listurl2($open, 5, 1, 0) . ">" . round($showDataArr[$bettype][1]['amount']) . "</td>";
}
else
{
    $list .= "<td align=right> 0</td>";
    $list .= "<td align=right> 0</td>";
}
$list .= "<td align=right> " . $showDataArr[$bettype]['1']['rate'] . "</td>";
if ($temp < 0)
{
    $list .= "<td align=right nowrap><font color='#EE2200'>" . $temp . "</font></td></tr>";
}
else
{
    $list .= "<td align=right nowrap><font color='#00AA22'>" . $temp . "</font></td></tr>";
}
$list .= "<tr class=td2>";
$list .= "<td class=td15 align=center>总双</td>";
$temp = round($dataTotalArr[$bettype]['amount'] - $showDataArr[$bettype]['2']['amount_rate'] - $dataTotalArr[$bettype]['back1'] + $dataTotalArr[$bettype]['back2']);
if (0 < $showDataArr[$bettype]['2']['totalnum'])
{
    $alert = $showDataArr[$bettype]['2']['namount'];
    $list .= "<td align=right nowrap>" . $showDataArr[$bettype]['2']['totalnum'] . "</td>";
    $list .= "<td align=right nowrap><a href=" . get_listurl2($open, 5, 2, 0) . ">" . round($showDataArr[$bettype][2]['amount']) . "</td>";
}
else
{
    $list .= "<td align=right> 0</td>";
    $list .= "<td align=right> 0</td>";
}
$list .= "<td align=right> " . $showDataArr[$bettype]['2']['rate'] . "</td>";
if ($temp < 0)
{
    $list .= "<td align=right nowrap><font color='#EE2200'>" . $temp . "</font></td></tr>";
}
else
{
    $list .= "<td align=right nowrap><font color='#00AA22'>" . $temp . "</font></td></tr>";
}
$list .= "<tr class=td6>";
$list .= "<td class=td0 align=right>合计</td>";
$list .= "<td align=right>" . intval($dataTotalArr[$bettype]['totalnum']) . "</td>";
$list .= "<td align=right>" . round($dataTotalArr[$bettype]['amount']) . "</td><td></td><td></td></tr>";
$tpl->set("list1", $list);
$bettype = 6;
$list = "";
$list .= "<tr class=td2>";
$list .= "<td class=td15 align=center>总大</td>";
$temp = round($dataTotalArr[$bettype]['amount'] - $showDataArr[$bettype]['1']['amount_rate'] - $dataTotalArr[$bettype]['back1'] + $dataTotalArr[$bettype]['back2']);
if (0 < $showDataArr[$bettype]['1']['totalnum'])
{
    $alert = $showDataArr[$bettype]['1']['namount'];
    $list .= "<td align=right nowrap>" . $showDataArr[$bettype]['1']['totalnum'] . "</td>";
    $list .= "<td align=right {$alert} nowrap><a href=" . get_listurl2($open, 6, 1, 0) . ">" . round($showDataArr[$bettype]['1']['amount']) . "</td>";
}
else
{
    $list .= "<td align=right> 0</td>";
    $list .= "<td align=right> 0</td>";
}
$list .= "<td align=right> " . $showDataArr[$bettype]['1']['rate'] . "</td>";
if ($temp < 0)
{
    $list .= "<td align=right nowrap><font color='#EE2200'>" . $temp . "</font></td></tr>";
}
else
{
    $list .= "<td align=right nowrap><font color='#00AA22'>" . $temp . "</font></td></tr>";
}
$list .= "<tr class=td2>";
$list .= "<td class=td15 align=center nowrap>总小</td>";
$temp = round($dataTotalArr[$bettype]['amount'] - $showDataArr[$bettype]['2']['amount_rate'] - $dataTotalArr[$bettype]['back1'] + $dataTotalArr[$bettype]['back2']);
if (0 < $showDataArr[$bettype]['2']['totalnum'])
{
    $alert = $showDataArr[$bettype]['2']['namount'];
    $list .= "<td align=right nowrap>" . $showDataArr[$bettype]['2']['totalnum'] . "</td>";
    $list .= "<td align=right {$alert} nowrap><a href=" . get_listurl2($open, 6, 2, 0) . ">" . round($showDataArr[$bettype]['2']['amount']) . "</td>";
}
else
{
    $list .= "<td align=right> 0</td>";
    $list .= "<td align=right> 0</td>";
}
$list .= "<td align=right> " . $showDataArr[$bettype]['2']['rate'] . "</td>";
if ($temp < 0)
{
    $list .= "<td align=right nowrap><font color='#EE2200'>" . $temp . "</font></td></tr>";
}
else
{
    $list .= "<td align=right nowrap><font color='#00AA22'>" . $temp . "</font></td></tr>";
}
$list .= "";
$list .= "<tr class=td6>";
$list .= "<td class=td0 align=right>合计</td>";
$list .= "<td align=right>" . intval($dataTotalArr[$bettype]['totalnum']) . "</td>";
$list .= "<td align=right>" . round($dataTotalArr[$bettype]['amount']) . "</td><td></td><td></td></tr>";
$tpl->set("list2", $list);
$i = 1;
while ($i <= 6)
{
    $bettype = "15_{$i}";
    $numberStr = "{$i} 1";
    $temp = round($dataTotalArr[$bettype]['amount'] - $showDataArr[$bettype][$numberStr]['amount_rate'] - $dataTotalArr[$bettype]['back1'] + $dataTotalArr[$bettype]['back2']);
    if (0 < $showDataArr[$bettype][$numberStr]['totalnum'])
    {
        $alert = $showDataArr[$bettype][$numberStr]['namount'];
        $tmp = "<td>" . $showDataArr[$bettype][$numberStr]['totalnum'] . "</td><td {$alert}><a href=" . get_listurl($open, 15, $i . " 1") . ">" . round($showDataArr[$bettype][$numberStr]['amount']) . "</td>";
    }
    else
    {
        $tmp = "<td> 0</td><td> 0</td>";
    }
    $tmp .= "<td> " . $showDataArr[$bettype][$numberStr]['rate'] . "</td>";
    if ($temp < 0)
    {
        $tmp .= "<td align=right><font color='#EE2200'>" . $temp . "</font></td>";
    }
    else
    {
        $tmp .= "<td align=right><font color='#00AA22'>" . $temp . "</font></td>";
    }
    $numberStr = "{$i} 2";
    $temp = round($dataTotalArr[$bettype]['amount'] - $showDataArr[$bettype][$numberStr]['amount_rate'] - $dataTotalArr[$bettype]['back1'] + $dataTotalArr[$bettype]['back2']);
    if (0 < $showDataArr[$bettype][$numberStr]['totalnum'])
    {
        $alert = $showDataArr[$bettype][$numberStr]['namount'];
        $tmp .= "<td>" . $showDataArr[$bettype][$numberStr]['totalnum'] . "</td><td {$alert}><a href=" . get_listurl($open, 15, $i . " 2") . ">" . round($showDataArr[$bettype][$numberStr]['amount']) . "</td>";
    }
    else
    {
        $tmp .= "<td> 0</td><td> 0</td>";
    }
    $tmp .= "<td> " . $showDataArr[$bettype][$numberStr]['rate'] . "</td>";
    if ($temp < 0)
    {
        $tmp .= "<td align=right><font color='#EE2200'>" . $temp . "</font></td>";
    }
    else
    {
        $tmp .= "<td align=right><font color='#00AA22'>" . $temp . "</font></td>";
    }
    $tmp .= "<td class=td6>" . intval($dataTotalArr[$bettype]['totalnum']) . "</td><td class=td6>" . round($dataTotalArr[$bettype]['amount']) . "</td>";
    $tmp .= "<td class=td2></td>";
    $bettype = "16_{$i}";
    $numberStr = "{$i} 3";
    $temp = round($dataTotalArr[$bettype]['amount'] - $showDataArr[$bettype][$numberStr]['amount_rate'] - $dataTotalArr[$bettype]['back1'] + $dataTotalArr[$bettype]['back2']);
    if (0 < $showDataArr[$bettype][$numberStr]['totalnum'])
    {
        $alert = $showDataArr[$bettype][$numberStr]['namount'];
        $tmp .= "<td>" . $showDataArr[$bettype][$numberStr]['totalnum'] . "</td><td {$alert}><a href=" . get_listurl($open, 16, $i . " 3") . ">" . round($showDataArr[$bettype][$numberStr]['amount']) . "</td>";
    }
    else
    {
        $tmp .= "<td> 0</td><td> 0</td>";
    }
    $tmp .= "<td> " . $showDataArr[$bettype][$numberStr]['rate'] . "</td>";
    if ($temp < 0)
    {
        $tmp .= "<td align=right><font color='#EE2200'>" . $temp . "</font></td>";
    }
    else
    {
        $tmp .= "<td align=right><font color='#00AA22'>" . $temp . "</font></td>";
    }
    $numberStr = "{$i} 4";
    $temp = round($dataTotalArr[$bettype]['amount'] - $showDataArr[$bettype][$numberStr]['amount_rate'] - $dataTotalArr[$bettype]['back1'] + $dataTotalArr[$bettype]['back2']);
    if (0 < $showDataArr[$bettype][$numberStr]['totalnum'])
    {
        $alert = $showDataArr[$bettype][$numberStr]['namount'];
        $tmp .= "<td>" . $showDataArr[$bettype][$numberStr]['totalnum'] . "</td><td {$alert}><a href=" . get_listurl($open, 16, $i . " 4") . ">" . round($showDataArr[$bettype][$numberStr]['amount']) . "</td>";
    }
    else
    {
        $tmp .= "<td> 0</td><td> 0</td>";
    }
    $tmp .= "<td> " . $showDataArr[$bettype][$numberStr]['rate'] . "</td>";
    if ($temp < 0)
    {
        $tmp .= "<td align=right><font color='#EE2200'>" . $temp . "</font></td>";
    }
    else
    {
        $tmp .= "<td align=right><font color='#00AA22'>" . $temp . "</font></td>";
    }
    $tmp .= "<td class=td6>" . intval($dataTotalArr[$bettype]['totalnum']) . "</td><td class=td6>" . round($dataTotalArr[$bettype]['amount']) . "</td>";
    $tpl->set("aa" . $i, $tmp);
    ++$i;
}
$i = 1;
while ($i <= 6)
{
    $bettype = "17_{$i}";
    $numberStr = "{$i} 5";
    $temp = round($dataTotalArr[$bettype]['amount'] - $showDataArr[$bettype][$numberStr]['amount_rate'] - $dataTotalArr[$bettype]['back1'] + $dataTotalArr[$bettype]['back2']);
    if (0 < $showDataArr[$bettype][$numberStr]['totalnum'])
    {
        $alert = $showDataArr[$bettype][$numberStr]['namount'];
        $tmp = "<td  nowrap>" . $showDataArr[$bettype][$numberStr]['totalnum'] . "</td><td {$alert}  nowrap><a href=" . get_listurl($open, 17, $i . " 5") . ">" . round($showDataArr[$bettype][$numberStr]['amount']) . "</td>";
    }
    else
    {
        $tmp = "<td> 0</td><td> 0</td>";
    }
    $tmp .= "<td  nowrap> " . $showDataArr[$bettype][$numberStr]['rate'] . "</td>";
    if ($temp < 0)
    {
        $tmp .= "<td align=right  nowrap><font color='#EE2200'>" . $temp . "</font></td>";
    }
    else
    {
        $tmp .= "<td align=right  nowrap><font color='#00AA22'>" . $temp . "</font></td>";
    }
    $numberStr = "{$i} 6";
    $temp = round($dataTotalArr[$bettype]['amount'] - $showDataArr[$bettype][$numberStr]['amount_rate'] - $dataTotalArr[$bettype]['back1'] + $dataTotalArr[$bettype]['back2']);
    if (0 < $showDataArr[$bettype][$numberStr]['totalnum'])
    {
        $alert = $showDataArr[$bettype][$numberStr]['namount'];
        $tmp .= "<td  nowrap>" . $showDataArr[$bettype][$numberStr]['totalnum'] . "</td><td {$alert}  nowrap><a href=" . get_listurl($open, 17, $i . " 6") . ">" . round($showDataArr[$bettype][$numberStr]['amount']) . "</td>";
    }
    else
    {
        $tmp .= "<td> 0</td><td> 0</td>";
    }
    $tmp .= "<td  nowrap> " . $showDataArr[$bettype][$numberStr]['rate'] . "</td>";
    if ($temp < 0)
    {
        $tmp .= "<td align=right  nowrap><font color='#EE2200'>" . $temp . "</font></td>";
    }
    else
    {
        $tmp .= "<td align=right  nowrap><font color='#00AA22'>" . $temp . "</font></td>";
    }
    $numberStr = "{$i} 7";
    $temp = round($dataTotalArr[$bettype]['amount'] - $showDataArr[$bettype][$numberStr]['amount_rate'] - $dataTotalArr[$bettype]['back1'] + $dataTotalArr[$bettype]['back2']);
    if (0 < $showDataArr[$bettype][$numberStr]['totalnum'])
    {
        $alert = $showDataArr[$bettype][$numberStr]['namount'];
        $tmp .= "<td nowrap>" . $showDataArr[$bettype][$numberStr]['totalnum'] . "</td><td {$alert} nowrap><a href=" . get_listurl($open, 17, $i . " 7") . ">" . round($showDataArr[$bettype][$numberStr]['amount']) . "</td>";
    }
    else
    {
        $tmp .= "<td> 0</td><td> 0</td>";
    }
    $tmp .= "<td nowrap> " . $showDataArr[$bettype][$numberStr]['rate'] . "</td>";
    if ($temp < 0)
    {
        $tmp .= "<td align=right nowrap><font color='#EE2200'>" . $temp . "</font></td>";
    }
    else
    {
        $tmp .= "<td align=right nowrap><font color='#00AA22'>" . $temp . "</font></td>";
    }
    $tmp .= "<td class=td6 nowrap>" . intval($dataTotalArr[$bettype]['totalnum']) . "</td><td class=td6 nowrap>" . round($dataTotalArr[$bettype]['amount']) . "</td>";
    $tmp .= "<td class=td2></td>";
    $bettype = "23_{$i}";
    $numberStr = "{$i} 8";
    $temp = round($dataTotalArr[$bettype]['amount'] - $showDataArr[$bettype][$numberStr]['amount_rate'] - $dataTotalArr[$bettype]['back1'] + $dataTotalArr[$bettype]['back2']);
    if (0 < $showDataArr[$bettype][$numberStr]['totalnum'])
    {
        $alert = $showDataArr[$bettype][$numberStr]['namount'];
        $tmp .= "<td nowrap>" . $showDataArr[$bettype][$numberStr]['totalnum'] . "</td><td {$alert} nowrap><a href=" . get_listurl($open, 23, $i . " 8") . ">" . round($showDataArr[$bettype][$numberStr]['amount']) . "</td>";
    }
    else
    {
        $tmp .= "<td> 0</td><td> 0</td>";
    }
    $tmp .= "<td nowrap> " . $showDataArr[$bettype][$numberStr]['rate'] . "</td>";
    if ($temp < 0)
    {
        $tmp .= "<td align=right nowrap><font color='#EE2200'>" . $temp . "</font></td>";
    }
    else
    {
        $tmp .= "<td align=right nowrap><font color='#00AA22'>" . $temp . "</font></td>";
    }
    $numberStr = "{$i} 9";
    $temp = round($dataTotalArr[$bettype]['amount'] - $showDataArr[$bettype][$numberStr]['amount_rate'] - $dataTotalArr[$bettype]['back1'] + $dataTotalArr[$bettype]['back2']);
    if (0 < $showDataArr[$bettype][$numberStr]['totalnum'])
    {
        $alert = $showDataArr[$bettype][$numberStr]['namount'];
        $tmp .= "<td nowrap>" . $showDataArr[$bettype][$numberStr]['totalnum'] . "</td><td {$alert} nowrap><a href=" . get_listurl($open, 23, $i . " 9") . ">" . round($showDataArr[$bettype][$numberStr]['amount']) . "</td>";
    }
    else
    {
        $tmp .= "<td> 0</td><td> 0</td>";
    }
    $tmp .= "<td nowrap> " . $showDataArr[$bettype][$numberStr]['rate'] . "</td>";
    if ($temp < 0)
    {
        $tmp .= "<td align=right nowrap><font color='#EE2200'>" . $temp . "</font></td>";
    }
    else
    {
        $tmp .= "<td align=right nowrap><font color='#00AA22'>" . $temp . "</font></td>";
    }
    $tmp .= "<td class=td6 nowrap>" . intval($dataTotalArr[$bettype]['totalnum']) . "</td><td class=td6 nowrap>" . round($dataTotalArr[$bettype]['amount']) . "</td>";
    $tpl->set("ab" . $i, $tmp);
    ++$i;
}
$tpl->load("main", "onlinebet2.htm");
$tpl->show("main");
$ui->footer();